/**
 * 用户权限等级映射（与后端 JurisdictionLevel 枚举保持一致）
 */
export const userJurisdictionLevel = {
    ROOT_JURISDICTION: {
        level: 114514,
        name: 'root用户',
    },
    ADMIN_JURISDICTION: {
        level: 6,
        name: '用户管理员',
    },
    RESOURCES_ADMIN_JURISDICTION: {
        level: 5,
        name: '资源管理员',
    },
    USERS_JURISDICTION: {
        level: 3,
        name: '一般用户',
    },
    NOT_VALIDATED: {
        level: 2,
        name: '未激活邮箱的用户',
    },
    TOURIST_JURISDICTION: {
        level: 0,
        name: '游客',
    },
    RESOURCES_SHARE_JURISDICTION: {
        level: 4,
        name: "资源分享者",
    }

} as const

/**
 * 权限等级列表（已按等级降序排序）
 */
export const sortedJurisdictionLevels = Object.values(userJurisdictionLevel).sort(
    (a, b) => b.level - a.level
)

/**
 * 根据权限 level 返回匹配的权限对象（模仿后端二分查找逻辑）
 */
export function getJurisdictionByLevel(level: number) {
    for (const item of sortedJurisdictionLevels) {
        if (level >= item.level) {
            return item
        }
    }
    throw new Error('错误!不存在的权限等级信息!!')
}
